﻿using MusicExplorer.Model;
using SQLite;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MusicExplorer.Data.Model
{
    [Table("Entities")]
    internal sealed class Entity
    {
        public static Entity New(MusicExplorer.Model.Entity entityModel)
        {
            try
            {
                var entity = new Entity()
                {
                    ModelId = entityModel.Id,
                    EntityName = entityModel.Name,
                    RepositoryId = entityModel.Repository.Id,
                    EntityType = entityModel.Type
                };

                switch (entityModel.Type)
                {
                    case EntityType.Youtube:
                        var youtube = (Youtube)entityModel;
                        entity.Param1 = youtube.PlaylistId;
                        entity.Param2 = youtube.PlaylistName;
                        return entity;
                    case EntityType.Artist:
                        var artist = (Artist)entityModel;
                        entity.Param1 = artist.SmallArtwork;
                        entity.Param2 = artist.BigArtwork;
                        return entity;
                    case EntityType.Genre:
                    case EntityType.Label:
                    case EntityType.WebSite:
                    case EntityType.Soundcloud:
                        return entity;
                    default:
                        throw new Exception("Not supported entity type");
                }
            }
            catch(Exception ex)
            {
                throw ex;
            }
        }

        //[PrimaryKey, Unique]
        //public int DatabaseId { get; set; }
        [MaxLength(255)]
        public string ModelId { get; set; }
        public Guid RepositoryId { get; set; }
        [MaxLength(255)]
        public string EntityName { get; set; }
        public EntityType EntityType { get; set; }

        /// <summary>
        /// PARAM1
        /// </summary>
        [MaxLength(255)]
        public string Param1 { get; set; }

        /// <summary>
        /// PARAM2
        /// </summary>
        [MaxLength(255)]
        public string Param2 { get; set; }
    }
}
